/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extensions.games;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Manu
 */
public class GameManager
{
    private Map<String, AbstractGame> _games;
    private static GameManager _instance;
    
    private GameManager()
    {
        _games = new HashMap<String, AbstractGame>();
    }
    
    public static GameManager getInstance()
    {
        if (_instance == null)
            _instance = new GameManager();
        
        return _instance;
    }
    
    public Collection<AbstractGame> getGames()
    {
	return _games.values();
    }
    
    public void registerGame(AbstractGame game)
    {
        if (_games.containsKey(game.getName()))
            throw new IllegalArgumentException("Game name duplicated:"+game.getName());
        
        _games.put(game.getName(), game);
    }
    
    public AbstractGame getGame(String name)
    {
        if (_games.containsKey(name))
            throw new IllegalArgumentException("Game '"+name+"' is not registered.");
        
        return _games.get(name);
    }
    
    public String[] getGameNames()
    {
        return _games.keySet().toArray(new String[_games.size()]);
    }
    
}
